@echo off
echo Starting ZhijiaoCloud Application...
echo.

REM 设置项目根目录
set PROJECT_ROOT=%~dp0
cd /d "%PROJECT_ROOT%"

REM 检查是否已编译
if not exist "zjcloud-admin\target\classes" (
    echo Compiling project...
    call mvn clean compile -DskipTests
    if errorlevel 1 (
        echo Compilation failed!
        pause
        exit /b 1
    )
)

REM 检查依赖是否已复制
if not exist "zjcloud-admin\target\lib" (
    echo Copying dependencies...
    cd zjcloud-admin
    call mvn dependency:copy-dependencies -DoutputDirectory=target/lib
    cd ..
    if errorlevel 1 (
        echo Failed to copy dependencies!
        pause
        exit /b 1
    )
)

echo.
echo Starting application with complete classpath...
echo.

REM 构建完整的类路径
set CLASSPATH=zjcloud-admin\target\classes
set CLASSPATH=%CLASSPATH%;zjcloud-admin\target\lib\*
set CLASSPATH=%CLASSPATH%;zjcloud-common\target\classes
set CLASSPATH=%CLASSPATH%;zjcloud-framework\target\classes
set CLASSPATH=%CLASSPATH%;zjcloud-system\target\classes
set CLASSPATH=%CLASSPATH%;zjcloud-quartz\target\classes
set CLASSPATH=%CLASSPATH%;zjcloud-generator\target\classes
set CLASSPATH=%CLASSPATH%;zjcloud-besigheid\target\classes
set CLASSPATH=%CLASSPATH%;zjcloud-academic\target\classes

REM 启动应用程序
java -cp "%CLASSPATH%" com.zjcloud.RuoYiApplication

if errorlevel 1 (
    echo.
    echo Application failed to start!
    echo.
    echo If you see NoClassDefFoundError, please try:
    echo 1. Run: mvn clean install -DskipTests
    echo 2. Use Spring Boot way: mvn spring-boot:run
    echo.
    pause
)